package com.zijin.controller.user;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zijin.PageQureyDTO;
import com.zijin.dto.user.RolePathDto;
import com.zijin.result.PageResult;
import com.zijin.result.Result;
import com.zijin.service.user.IRolePathService;
import com.zijin.vo.user.RolePathVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Set;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author JWei Xu
 * @since 2025-02-03
 */

@Api(tags = "角色允许访问的路径")
@RestController
@RequestMapping("/base/rolePath")
public class RolePathController {

    @Resource
    IRolePathService rolePathService;


    @ApiOperation("增加允许的路径")
    @GetMapping("/allowedRoutes")
    public Result<Set<String>> allowedRoutes(){
        return Result.success(rolePathService.allowedRoutes());
    }

    @ApiOperation("分页查询")
    @GetMapping("/getPage")
    public Result<PageResult<RolePathVo>> getPage(PageQureyDTO dto){
        Page<RolePathVo> page = rolePathService.getPage(dto);
        return Result.success(new PageResult<>(page.getTotal(),page.getRecords()));
    }

    @ApiOperation("增加一个")
    @PostMapping("/addOne")
    public Result<Boolean> addOne(@RequestBody @Valid RolePathDto rolePathDto){
        return Result.success(rolePathService.addOne(rolePathDto));
    }

    @ApiOperation("查询所有允许的路径")
    @DeleteMapping("/delOne/{id}")
    public Result<Boolean> delOne(@PathVariable Long id){
        return Result.success(rolePathService.delOne(id));
    }



}
